using UnityEngine;

public class Achi_item : MonoBehaviour
{
	public int achi_index;

	public UISprite[] stars;

	public UILabel infolabel;

	public UISprite scrollsp;

	public UILabel scrolllabel;

	public UIWidget notfinishwi;

	public UISprite rewardflag;

	public UILabel rewardlabel;

	public UISprite claimsp;

	public UIWidget finishwi;

	public UIEventListener claimbtn;

	public UISprite finishsp;

	public TweenScale completeanima;

	private int starinfo;

	private int achiitemnum;

	private AchievementData curitemdata;

	private bool isclick;

	private bool isfinish;

	private void Start()
	{
		claimbtn.onClick = OnClickclaimBtn;
	}

	public bool enable(int ind)
	{
		achi_index = ind;
		starinfo = MenuPlayerprefs.instance.ds_star_achi[achi_index];
		achiitemnum = MenuPlayerprefs.instance.ds_item_achi[achi_index];
		curitemdata = MenuDataController.instance.AchiData[achi_index];
		isclick = false;
		isfinish = false;
		showinfo();
		return isfinish;
	}

	public void showinfo()
	{
		for (int i = 0; i < 3; i++)
		{
			if (starinfo > i)
			{
				stars[i].enabled = true;
			}
			else
			{
				stars[i].enabled = false;
			}
		}
		if (starinfo >= 3)
		{
			infolabel.text = GetDescinfo(2);
			scrollsp.fillAmount = 1f;
			scrolllabel.text = curitemdata.num[2] + "/" + curitemdata.num[2];
			finishwi.alpha = 1f; finishwi.gameObject.SetActive(true);
			if (isclick)
			{
				completeanima.PlayForward();
			}
			notfinishwi.alpha = 0f; notfinishwi.gameObject.SetActive(false);
			finishsp.enabled = false;
			claimsp.transform.parent.gameObject.SetActive(false);
		}
		else
		{
			claimsp.transform.parent.gameObject.SetActive(true);
			infolabel.text = GetDescinfo(starinfo);
			scrollsp.fillAmount = (float)achiitemnum / (float)curitemdata.num[starinfo];
			scrolllabel.text = achiitemnum + "/" + curitemdata.num[starinfo];
			finishwi.alpha = 0f; finishwi.gameObject.SetActive(false);
			notfinishwi.alpha = 1f; notfinishwi.gameObject.SetActive(true);
			switch (curitemdata.rewardtype[starinfo])
			{
				case 0:
					rewardflag.spriteName = "GY_zuanShi_01";
					break;
				case 1:
					rewardflag.spriteName = "CZ_jinBi_02";
					break;
			}
			rewardlabel.text = string.Empty + curitemdata.rewardnum[starinfo];
			if (curitemdata.num[starinfo] <= achiitemnum)
			{
				claimsp.spriteName = "JS_anNiu";
				finishsp.enabled = true;
				isfinish = true;
			}
			else
			{
				claimsp.spriteName = "JS_anNiuHui";
				finishsp.enabled = false;
			}
		}
		isclick = false;
	}

	public string GetDescinfo(int numind)
	{
		switch (achi_index)
		{
			case 0:
				return "完成关卡 " + curitemdata.num[numind] + "-6";
			case 1:
				return "完成关卡 " + curitemdata.num[numind] + "-6";
			case 2:
				return "拥有 " + curitemdata.num[numind] + " 架飞机";
			case 3:
				return "解锁 " + curitemdata.num[numind] + " 把机枪";
			case 4:
				return "解锁 " + curitemdata.num[numind] + " 枚远程导弹";
			case 5:
				return "解锁 " + curitemdata.num[numind] + "  枚多目标导弹";
			case 6:
				return "击落 " + curitemdata.num[numind] + "  架敌机";
			case 7:
				return "击沉 " + curitemdata.num[numind] + " 艘战舰";
			case 8:
				return "摧毁 " + curitemdata.num[numind] + " 栋建筑";
			case 9:
				return "被敌人击杀 " + curitemdata.num[numind] + " 次";
			case 10:
				return "挑战模式游玩 " + curitemdata.num[numind] + " 次";
			case 11:
				return "在生存模式（简单）中通过 " + curitemdata.num[numind] + " 波";
			case 12:
				return "在生存模式（普通）中通过 " + curitemdata.num[numind] + " 波";
			case 13:
				return "在生存模式（困难）中通过 " + curitemdata.num[numind] + " 波";
			case 14:
				return "在团队死亡竞赛中击落 " + curitemdata.num[numind] + " 架敌机";
			case 15:
				return "在自由对抗中连续击落 " + curitemdata.num[numind] + " 架飞机";
			case 16:
				return "赢得保卫基地 " + curitemdata.num[numind] + " 次";
			case 17:
				return "安全着陆 " + curitemdata.num[numind] + " 次.";
			default:
				return string.Empty;
		}
	}

	public void OnClickclaimBtn(GameObject btn)
	{
		if (curitemdata.num[starinfo] <= achiitemnum)
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_getmoney, 0f);
			MenuPlayerprefs.instance.savestarachi(achi_index);
			switch (curitemdata.rewardtype[starinfo])
			{
				case 0:
					MenuPlayerprefs.instance.AddDiamod(curitemdata.rewardnum[starinfo], late: true);
					MenuUIController.instance.enable_effectui(rewardflag.transform.position, 1);
					MonoInstance<AudioController>.instance.play(AudioType.UI_getdiamond, 0f);
					break;
				case 1:
					MenuPlayerprefs.instance.AddMoney(curitemdata.rewardnum[starinfo], late: true);
					MenuUIController.instance.enable_effectui(rewardflag.transform.position, 0);
					MonoInstance<AudioController>.instance.play(AudioType.UI_getmoney, 0f);
					break;
			}
			starinfo++;
			isclick = true;
			isfinish = false;
			showinfo();
		}
		else
		{
			MonoInstance<AudioController>.instance.play(AudioType.UI_pophit, 0f);
		}
	}
}
